package com.ruoyi.websocket;

/**
 * @projectName: ruoyi
 * @package: com.ruoyi.websocket
 * @className: WebSocketConnect
 * @author: 徐源长
 * @description:
 */




import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessageRole;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class WebSocketConnect {
    private String session;
    private List<ChatMessage> messages;

    public WebSocketConnect(String session) {
        this.session = session;
        this.messages = new ArrayList<>();
        ChatMessage systemMessage = ChatMessage.builder().role(ChatMessageRole.SYSTEM).content("你是一个智能小助手，需要根据自己的知识简洁地回答用户问题,尽量以200字以内作答").build();
        messages.add(systemMessage);
    }


    public void addUserMessage(String message) {
        ChatMessage userMessage = ChatMessage.builder().role(ChatMessageRole.USER).content(message).build();
        messages.add(userMessage);
    }


    public void addAssistantMessage(String message) {
        ChatMessage assistantMessage = ChatMessage.builder().role(ChatMessageRole.ASSISTANT).content(message).build();
        messages.add(assistantMessage);
    }

    public String reply(String message) {
        addUserMessage(message);
        String response = apiRequest.request(this.getMessages());
        addAssistantMessage(response);
        return response;
    }
}
